<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>公告通知管理</title>
    <#include "/common/link.ftl">
    <script>
       /* $(function () {
            $('.input-date').datetimepicker({
                format: 'yyyy-mm-dd ', //格式
                language: 'zh-CN', //中文
                autoclose: true,//选择后自动关闭
                showMeridian: true, //是否显示上下午
                minView: 2,//精确到哪位
            });*/
    </script>

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="notice"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>公告通知管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/notice/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">

                        <div class="form-group">
                            <label>创建日期查询：</label>
                            <input placeholder="请输入开始日期" type="text" class="form-control input-date"
                                   name="beginDate" value="${(qo.beginDate?string("yyyy-MM-dd"))!}"/> -
                            <input placeholder="请输入结束日期" type="text" class="form-control input-date"
                                   name="endDate" value="${(qo.endDate?string("yyyy-MM-dd"))!}"/>
                        </div>

                        <div class="form-group">
                            <label>公告级别：</label>
                            <select class="form-control" name="grade" id="gradeId">
                                <option value="-1">请选择级别</option>
                                <option value="0">普通</option>
                                <option value="1">重要</option>
                                <option value="2">紧急</option>

                                <#--<#list pageInfo.list as p >
                                    <option value="${p.grade}">${p.gradeDisplay}</option>
                                </#list>-->
                            </select>
                            <script>
                                $("#gradeId").val('${qo.grade}');
                            </script>
                        </div>
                        <div class="form-group">
                            <label>阅读状态：</label>
                            <select class="form-control" name="haveRead" id="haveReadId">
                                <option value="-1">全部</option>
                                <option value="0">未读</option>
                                <option value="1">已读</option>

                                <#-- <#list pageInfo.list as p >
                                     <option value="${p.haveRead}">${p.haveReadDisplay}</option>
                                 </#list>-->
                            </select>
                            <script>
                                $("#haveReadId").val('${qo.haveRead}')
                            </script>
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>
                            查询
                        </button>

                        <a href="#" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>公告标题</th>
                            <th>创建人</th>
                            <th>创建时间</th>
                            <th>公告级别</th>
                            <th>是否已读</th>
                            <th>发布状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list pageInfo.list as p >
                            <tr>
                                <td>${p_index +1 !}</td>
                                <td>${p.name !}</td>
                                <td>${p.creator !}</td>
                                <td>${(p.creationTime?string("yyyy-MM-dd")) !}</td>
                                <td>${p.gradeDisplay !}</td>
                                <td>${p.haveReadDisplay !}</td>
                                <td>${p.postStatusDisplay !}</td>
                                <td>
                                    <a <#--href="/notice/show?id=${p.id} "--> class="btn btn-success btn-xs  btn-show" data-status="1" data-id="${p.id}"  >
                                        <span class="glyphicon glyphicon-phone-alt"></span> 查看</a>
                                    <a class="btn btn-primary btn-xs btn-input" data-json='${p.toJson()}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a class="btn btn-xs btn-info btn-push" data-status="1"  data-id="${p.id}">
                                        <span class="glyphicon glyphicon-share"></span> 发布</a>
                                    <a class="btn btn-xs btn-danger btn-remove" data-url="/notice/delete?id=${p.id}">
                                        <span class="glyphicon glyphicon-remove"></span> 取消</a>
                                </td>
                            </tr>
                        </#list>

                        </tbody>
                    </table>
                    <#include "/common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>

<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/notice/saveOrUpdate" method="post">
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告标题：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" id="name" name="name" placeholder="请输入公告标题"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告内容：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control" id="content" name="content" rows="8"
                                      placeholder="请输入公告内容"></textarea>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">公告级别：</label>
                        <div class="col-sm-7">
                            <select class="form-control" id="grade" name="grade" >
                                <option value="">请选择级别</option>
                                <option value="0">普通</option>
                                <option value="1">重要</option>
                                <option value="2">紧急</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(".btn-input").click(function () {

        // $("#editForm").clearForm(true);
        //
        // var json = $(this).data("json");
        //
        // console.log(json);
        var $btn = $(this);
        var data = $btn.data('json');

        // 清楚模态框之前显示的数据
        $('#editForm input[name]').val('');

        if (data) {

            $('#editForm input[name=id]').val(data.id);
            $('#editForm input[name=name]').val(data.name);
            $('#editForm select[name=grade]').val(data.grade);
            $('#editForm textarea[name=content]').val(data.content);

        }

        $(".modal").modal('show')

    });
    // 发布
    $(".btn-push").click(function () {

        var status = $(this).data("status");
        var id = $(this).data("id");
        console.log(status)

        Swal.fire({
            title: "确定发布公告吗!!",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '确定',
            cancelButtonText: '取消!'
        }).then((result) => {
            if(result.value) {
                window.location.href = "/notice/updateStatus?id=" + id + "&postStatus=" + status;
            }
        });
    });
    // 查看
    $(".btn-show").click(function () {

        var status = $(this).data("status");
        var id = $(this).data("id");

        Swal.fire({
            title: "你确定查看吗",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '确定',
            cancelButtonText: '取消!'
        }).then((result) => {
            if(result.value) {
                window.location.href = "/notice/show?id=" + id + "&haveRead=" + status;
            }
        });
    })

    // 取消
    $(function () {
        $('.btn-remove').click(function () {
            var url = $(this).data('url');
            console.log(url);
            Swal.fire({
                title: '您确定取消摸?',
                text: "此操作不可撤销!",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确定',
                cancelButtonText: '取消!'
            }).then((result) => {
                if(result.value) {
                    location.href = url;
                }
            });
        });
    });
</script>

</body>
</html>
